package com.example.thirdhomework

import android.content.Intent
import android.os.Bundle
import android.provider.MediaStore
import android.widget.EditText
import androidx.activity.enableEdgeToEdge
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.example.thirdhomework.databinding.ActivityMainBinding

//import com.example.demo.databinding.ActivityMainBinding;
const val KEY1="key1"
const val KEY2="key2"
class MainActivity : AppCompatActivity() {
    private lateinit var binding: ActivityMainBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        binding.button.setOnClickListener {
            val intent = Intent(this,FirstActivity::class.java)
            intent.putExtra(KEY1,binding.editTextText.text.toString())
            startActivity(intent)
        }
        binding.buttonSecond.setOnClickListener {
            val intent = Intent(this,SecondActivity::class.java)
            startActivityForResult(intent,1)
        }
        binding.buttonFifth.setOnClickListener {
            val intent = Intent(this,FourhActivity::class.java)
            startActivity(intent)
        }
        binding.buttonFourth.setOnClickListener {
            val intent = Intent(this,FifthActivity::class.java)
            startActivity(intent)
        }
    }
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode== RESULT_OK && requestCode==1){
            val str=data?.getStringExtra(KEY2)
            binding.textView.text=str
        }
    }

}